﻿
using Dovey_Study.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Dovey_Study.Controllers
{
    public class FirstController : Controller
    {
        private readonly ILogger<FirstController> _logger = null;
        private readonly IConfiguration _configuration;
        private readonly CustomerInfo _customerInfo;
        public FirstController(ILogger<FirstController> logger, IConfiguration configuration,IOptions<CustomerInfo> CustomerInfo) 
        {
            _logger = logger;
            _configuration = configuration;
            _customerInfo = CustomerInfo.Value;
        }

        // GET: FistController
        public ActionResult Index()
        {
            //ViewBag.parameter = _configuration["kkkkk"]; // 通过控制台的参数可以引入：   dotnet xxx.dll --kkkk "MMMMM"

            object obj = JsonConvert.SerializeObject(_customerInfo);
            return View(obj);
        }

        // GET: FistController/Details/5
        public ActionResult Details(int id)
        {
           
            return View();
        }

        // GET: FistController/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: FistController/Create
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: FistController/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: FistController/Edit/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: FistController/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: FistController/Delete/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }
    }
}
